package org.lee.jfm;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtils;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.jdbc.JDBCCategoryDataset;

import java.io.File;
import java.io.IOException;

/**
 * MySqlChartDemo
 * 从mysql读数据显示图表
 *
 * @author dralee
 * @date 2021-12-29 15:44:00
 **/
public class MySqlChartDemo {

    public static void main(String[] args) throws IOException {
        GoldMedalsLondonDao dao = new GoldMedalsLondonDao();
        JDBCCategoryDataset dataset = dao.getList();
        JFreeChart chart = ChartFactory.createBarChart("Olympic Gold medals in London", "",
                "Gold medals", dataset, PlotOrientation.VERTICAL, false, true, false);
        ChartUtils.saveChartAsPNG(new File("medals.png"), chart, 500, 450);
    }

}
